﻿using UnityEngine;
using System.Collections;
using System.Reflection; 

public static class ReflectionTools
{
    /// <summary>
    /// 反射获取私有字段
    /// </summary>
    public static T GetNonPublicField<T>(object obj, string fieldName)
    {
        FieldInfo fi = obj.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
        return (T)fi.GetValue(obj);
    }

    /// <summary>
    /// 反射设置私用字段
    /// </summary>
    public static void SetNonPublicField(object obj, string fieldName, object value)
    {
        FieldInfo fi = obj.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
        fi.SetValue(obj, value);
    }
}
